# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 读取Excel文件.py
Author: kij
Create Date: 2021/2/9
-------------------------------------------------
"""
import os
from openpyxl import load_workbook
from openpyxl import workbook


def get_file_path(file_name):
	return os.path.join(os.path.dirname(os.path.abspath(__file__)), "files", file_name)


# file_path = get_file_path('p1.xlsx')
# wb = load_workbook(file_path)
# print(wb.sheetnames)
# # 根据sheet名称选择sheet
# sheet = wb["数据导出"]
# cell = sheet.cell(1,2)
# print(cell.value)
# # 根据sheet名称选择sheet
# sheet = wb.worksheets[0]
# cell = sheet.cell(1,2)
# print(cell.value)
# # 循环所有sheet
# for name in wb.sheetnames:
# 	sheet = wb[name]
# 	print(sheet.cell(1,1).value)
# for sheet in wb.worksheets:
# 	cell = sheet.cell(1,1)
# 	print(cell.value)
# # 获取信息
# sheet = wb.worksheets[0]
# cell = sheet.cell(1,1)
# print(cell.value)
# print(cell.style)
# print(cell.font)
# print(cell.alignment)

# # 获取某个单元格
# sheet = wb.worksheets[0]
# c1 = sheet['A2']
# print(c1.value)
# # 获取第N行的所有单元格
# print(sheet[1])
# for cell in sheet[1]:
# 	print(cell.value)
# # 获取所有行的数据 sheet.rows
# for row in sheet.rows:
# 	print(row[3].value)
# 获取所有列的数据
# sheet = wb.worksheets[2]
# for row in sheet.rows:
# 	print(row)

# 修改excel内容
# wb = workbook.Workbook()
# sheet = wb.worksheets[0]
# sheet.title = "表格一"
# 创建sheet 并修改颜色
# sheet = wb.create_sheet('工作计划', 0)
# sheet.sheet_properties.tabColor = "FF0000"
# 打开默认的sheet
# wb.active = 0
# 拷贝sheet
# sheet = wb.create_sheet("工作计划")
# sheet.sheet_properties.tabColor = "00FF00"
# new_sheet = wb.copy_worksheet(wb["Sheet"])
# new_sheet.title = "新计划"
# wb.save(get_file_path("p2.xlsx"))

# # 删除sheet
# wb = load_workbook(get_file_path("p2.xlsx"))
# del wb['工作计划']
# wb.save(get_file_path("p2.xlsx"))